Josh Dillon, Last Revised January 2022
This notebook examines an individual antenna's performance over a whole season. This notebook parses information from each nightly rtp_summarynotebook (as saved to .csvs) and builds a table describing antenna performance. It also reproduces per-antenna plots from each auto_metrics notebook pertinent to the specific antenna.
import os
from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
# If you want to run this notebook locally, copy the output of the next cell into the next line of this cell.
# antenna = "004"
# csv_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/_rtp_summary_'
# auto_metrics_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/auto_metrics_inspect'
# os.environ["ANTENNA"] = antenna
# os.environ["CSV_FOLDER"] = csv_folder
# os.environ["AUTO_METRICS_FOLDER"] = auto_metrics_folder
# Use environment variables to figure out path to the csvs and auto_metrics
antenna = str(int(os.environ["ANTENNA"]))
csv_folder = os.environ["CSV_FOLDER"]
auto_metrics_folder = os.environ["AUTO_METRICS_FOLDER"]
print(f'antenna = "{antenna}"')
print(f'csv_folder = "{csv_folder}"')
print(f'auto_metrics_folder = "{auto_metrics_folder}"')
antenna = "98" csv_folder = "/home/obs/src/H6C_Notebooks/_rtp_summary_" auto_metrics_folder = "/home/obs/src/H6C_Notebooks/auto_metrics_inspect"
display(HTML(f'<h1 style=font-size:50px><u>Antenna {antenna} Report</u><p></p></h1>'))
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 1000)
import glob
import re
from hera_notebook_templates.utils import status_colors, Antenna
# load csvs and auto_metrics htmls in reverse chronological order
csvs = sorted(glob.glob(os.path.join(csv_folder, 'rtp_summary_table*.csv')))[::-1]
print(f'Found {len(csvs)} csvs in {csv_folder}')
auto_metric_htmls = sorted(glob.glob(auto_metrics_folder + '/auto_metrics_inspect_*.html'))[::-1]
print(f'Found {len(auto_metric_htmls)} auto_metrics notebooks in {auto_metrics_folder}')
Found 14 csvs in /home/obs/src/H6C_Notebooks/_rtp_summary_ Found 13 auto_metrics notebooks in /home/obs/src/H6C_Notebooks/auto_metrics_inspect
# Per-season options
mean_round_modz_cut = 4
dead_cut = 0.4
crossed_cut = 0.0
def jd_to_summary_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/_rtp_summary_/rtp_summary_{jd}.html'
def jd_to_auto_metrics_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/auto_metrics_inspect/auto_metrics_inspect_{jd}.html'
this_antenna = None
jds = []
# parse information about antennas and nodes
for csv in csvs:
df = pd.read_csv(csv)
for n in range(len(df)):
# Add this day to the antenna
row = df.loc[n]
if isinstance(row['Ant'], str) and '<a href' in row['Ant']:
antnum = int(row['Ant'].split('</a>')[0].split('>')[-1]) # it's a link, extract antnum
else:
antnum = int(row['Ant'])
if antnum != int(antenna):
continue
if np.issubdtype(type(row['Node']), np.integer):
row['Node'] = str(row['Node'])
if type(row['Node']) == str and row['Node'].isnumeric():
row['Node'] = 'N' + ('0' if len(row['Node']) == 1 else '') + row['Node']
if this_antenna is None:
this_antenna = Antenna(row['Ant'], row['Node'])
jd = [int(s) for s in re.split('_|\.', csv) if s.isdigit()][-1]
jds.append(jd)
this_antenna.add_day(jd, row)
break
# build dataframe
to_show = {'JDs': [f'<a href="{jd_to_summary_url(jd)}" target="_blank">{jd}</a>' for jd in jds]}
to_show['A Priori Status'] = [this_antenna.statuses[jd] for jd in jds]
df = pd.DataFrame(to_show)
# create bar chart columns for flagging percentages:
bar_cols = {}
bar_cols['Auto Metrics Flags'] = [this_antenna.auto_flags[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jee)'] = [this_antenna.dead_flags_Jee[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jnn)'] = [this_antenna.dead_flags_Jnn[jd] for jd in jds]
bar_cols['Crossed Fraction in Ant Metrics'] = [this_antenna.crossed_flags[jd] for jd in jds]
bar_cols['Flag Fraction Before Redcal'] = [this_antenna.flags_before_redcal[jd] for jd in jds]
bar_cols['Flagged By Redcal chi^2 Fraction'] = [this_antenna.redcal_flags[jd] for jd in jds]
for col in bar_cols:
df[col] = bar_cols[col]
z_score_cols = {}
z_score_cols['ee Shape Modified Z-Score'] = [this_antenna.ee_shape_zs[jd] for jd in jds]
z_score_cols['nn Shape Modified Z-Score'] = [this_antenna.nn_shape_zs[jd] for jd in jds]
z_score_cols['ee Power Modified Z-Score'] = [this_antenna.ee_power_zs[jd] for jd in jds]
z_score_cols['nn Power Modified Z-Score'] = [this_antenna.nn_power_zs[jd] for jd in jds]
z_score_cols['ee Temporal Variability Modified Z-Score'] = [this_antenna.ee_temp_var_zs[jd] for jd in jds]
z_score_cols['nn Temporal Variability Modified Z-Score'] = [this_antenna.nn_temp_var_zs[jd] for jd in jds]
z_score_cols['ee Temporal Discontinuties Modified Z-Score'] = [this_antenna.ee_temp_discon_zs[jd] for jd in jds]
z_score_cols['nn Temporal Discontinuties Modified Z-Score'] = [this_antenna.nn_temp_discon_zs[jd] for jd in jds]
for col in z_score_cols:
df[col] = z_score_cols[col]
ant_metrics_cols = {}
ant_metrics_cols['Average Dead Ant Metric (Jee)'] = [this_antenna.Jee_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Dead Ant Metric (Jnn)'] = [this_antenna.Jnn_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Crossed Ant Metric'] = [this_antenna.crossed_metrics[jd] for jd in jds]
for col in ant_metrics_cols:
df[col] = ant_metrics_cols[col]
redcal_cols = {}
redcal_cols['Median chi^2 Per Antenna (Jee)'] = [this_antenna.Jee_chisqs[jd] for jd in jds]
redcal_cols['Median chi^2 Per Antenna (Jnn)'] = [this_antenna.Jnn_chisqs[jd] for jd in jds]
for col in redcal_cols:
df[col] = redcal_cols[col]
# style dataframe
table = df.style.hide_index()\
.applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
.background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=list(z_score_cols.keys())) \
.background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=list(redcal_cols.keys())) \
.applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
.format({col: '{:,.4f}'.format for col in z_score_cols}) \
.format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
.format('{:,.2%}', na_rep='-', subset=list(bar_cols.keys())) \
.set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])
This table reproduces each night's row for this antenna from the RTP Summary notebooks. For more info on the columns, see those notebooks, linked in the JD column.
display(HTML(f'<h2>Antenna {antenna}, Node {this_antenna.node}:</h2>'))
HTML(table.render(render_links=True, escape=False))
| JDs | A Priori Status | Auto Metrics Flags | Dead Fraction in Ant Metrics (Jee) | Dead Fraction in Ant Metrics (Jnn) | Crossed Fraction in Ant Metrics | Flag Fraction Before Redcal | Flagged By Redcal chi^2 Fraction | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | Average Dead Ant Metric (Jee) | Average Dead Ant Metric (Jnn) | Average Crossed Ant Metric | Median chi^2 Per Antenna (Jee) | Median chi^2 Per Antenna (Jnn) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2459827 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.382738 | 14.408278 | 2.027328 | 1.416582 | 10.379716 | 12.184975 | 7.004963 | 3.969357 | 0.7333 | 0.6420 | 0.4150 | 12.544955 | 9.961005 |
| 2459826 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.618929 | 4.408798 | 1.381404 | 2.855589 | 0.947464 | 0.998754 | 0.573400 | 2.185840 | 0.7916 | 0.5230 | 0.5406 | 0.000000 | 0.000000 |
| 2459825 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 1.543848 | 1.543209 | 0.597432 | 2.390141 | -0.036245 | -0.503407 | 0.364626 | -0.472318 | 0.7952 | 0.5541 | 0.5258 | 2.630643 | 2.292053 |
| 2459824 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.574170 | 1.307619 | 1.685557 | 1.408176 | 1.477048 | 1.479493 | 0.570196 | 0.820760 | 0.6825 | 0.7093 | 0.3825 | 1.910684 | 2.021508 |
| 2459823 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.721086 | 1.848214 | 1.381465 | 3.193632 | 2.267821 | -0.094527 | 20.047806 | 4.246186 | 0.7486 | 0.6580 | 0.4127 | 66.875538 | 42.995406 |
| 2459822 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.468511 | 5.831967 | 0.783605 | 3.158203 | 0.321509 | -0.364252 | 3.863716 | -0.085432 | 0.7907 | 0.5608 | 0.5257 | 5.435048 | 5.836832 |
| 2459821 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 2.855770 | 16.308091 | 0.778987 | 2.386459 | -0.849238 | 6.359523 | -0.925050 | 0.110217 | 0.7891 | 0.5766 | 0.5195 | 4.939273 | 5.318684 |
| 2459820 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.776769 | 40.302846 | 1.181207 | 2.920012 | 0.887483 | 24.796942 | 1.500698 | 8.765674 | 0.7450 | 0.6328 | 0.4139 | 4.998102 | 5.104256 |
| 2459817 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 2.087357 | 1.232046 | 0.254780 | 2.729951 | -0.348081 | -0.414831 | -0.354952 | -0.387182 | 0.7940 | 0.6181 | 0.5207 | 2.083211 | 2.160426 |
| 2459816 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.898450 | 0.155929 | 1.488156 | 4.082724 | 2.096638 | 0.546343 | 3.937933 | 3.253416 | 0.8387 | 0.5652 | 0.6085 | 4.001535 | 4.459679 |
| 2459815 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.584473 | 3.400186 | -0.444969 | 3.993078 | 9.096844 | 0.421178 | 393.177359 | 3.162789 | 0.7952 | 0.6408 | 0.5168 | 3.970356 | 3.486497 |
| 2459814 | digital_ok | 0.00% | - | - | - | - | - | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan |
| 2459813 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 2.812876 | 10.807541 | 0.258510 | 8.076965 | 1.331599 | 23.931447 | 1.704898 | 2.814562 | 0.7659 | 0.7123 | 0.4169 | 7.029944 | 8.029348 |
auto_metrics notebooks.¶htmls_to_display = []
for am_html in auto_metric_htmls:
html_to_display = ''
# read html into a list of lines
with open(am_html) as f:
lines = f.readlines()
# find section with this antenna's metric plots and add to html_to_display
jd = [int(s) for s in re.split('_|\.', am_html) if s.isdigit()][-1]
try:
section_start_line = lines.index(f'<h2>Antenna {antenna}: {jd}</h2>\n')
except ValueError:
continue
html_to_display += lines[section_start_line].replace(str(jd), f'<a href="{jd_to_auto_metrics_url(jd)}" target="_blank">{jd}</a>')
for line in lines[section_start_line + 1:]:
html_to_display += line
if '<hr' in line:
htmls_to_display.append(html_to_display)
break
These figures are reproduced from auto_metrics notebooks. For more info on the specific plots and metrics, see those notebooks (linked at the JD). The most recent 100 days (at most) are shown.
for i, html_to_display in enumerate(htmls_to_display):
if i == 100:
break
display(HTML(html_to_display))
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | 14.408278 | 1.382738 | 14.408278 | 2.027328 | 1.416582 | 10.379716 | 12.184975 | 7.004963 | 3.969357 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | 4.408798 | 4.408798 | 1.618929 | 2.855589 | 1.381404 | 0.998754 | 0.947464 | 2.185840 | 0.573400 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Power | 2.390141 | 1.543209 | 1.543848 | 2.390141 | 0.597432 | -0.503407 | -0.036245 | -0.472318 | 0.364626 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | ee Power | 1.685557 | 0.574170 | 1.307619 | 1.685557 | 1.408176 | 1.477048 | 1.479493 | 0.570196 | 0.820760 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | ee Temporal Discontinuties | 20.047806 | 1.848214 | 1.721086 | 3.193632 | 1.381465 | -0.094527 | 2.267821 | 4.246186 | 20.047806 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | 5.831967 | 1.468511 | 5.831967 | 0.783605 | 3.158203 | 0.321509 | -0.364252 | 3.863716 | -0.085432 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | 16.308091 | 16.308091 | 2.855770 | 2.386459 | 0.778987 | 6.359523 | -0.849238 | 0.110217 | -0.925050 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | 40.302846 | 1.776769 | 40.302846 | 1.181207 | 2.920012 | 0.887483 | 24.796942 | 1.500698 | 8.765674 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Power | 2.729951 | 2.087357 | 1.232046 | 0.254780 | 2.729951 | -0.348081 | -0.414831 | -0.354952 | -0.387182 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Power | 4.082724 | 0.155929 | 1.898450 | 4.082724 | 1.488156 | 0.546343 | 2.096638 | 3.253416 | 3.937933 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | ee Temporal Discontinuties | 393.177359 | 3.400186 | 1.584473 | 3.993078 | -0.444969 | 0.421178 | 9.096844 | 3.162789 | 393.177359 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Shape | nan | nan | nan | nan | nan | nan | nan | nan | nan |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 98 | N07 | digital_ok | nn Temporal Variability | 23.931447 | 10.807541 | 2.812876 | 8.076965 | 0.258510 | 23.931447 | 1.331599 | 2.814562 | 1.704898 |